/*
 * billboard.cpp
 *
 *  Created on: 15.06.2012
 *      Author: Caffeine
 */



#include "billboard.h"
#include <lampe/xml/IXMLFactoryEnvironment.h>
#include "irrxml.h"
#include <lampe/xml/IXmlNode.h>
#include <ISceneNodeAnimator.h>
#include <ISceneManager.h>
#include "utils/base_scenenode.h"

namespace lampe{
namespace xml{

class BillboardFactory:public IIrrXmlNode{
public:
	BillboardFactory(irr::IrrlichtDevice*d):IIrrXmlNode(d){}
	virtual LAMPE_VECTOR_VENDOR<String> getProcessedTags(){
		LAMPE_VECTOR_VENDOR<String> list;
		list.push_back("billboard");
		return list;
	};

	virtual lampe::xml::TagResult tagHandlerBefor(lampe::xml::IXMLFactoryEnvironment*environment,lampe::xml::IXmlNode*node){
		irr::scene::ISceneNode*parent=0;

		if ((node->getParent()) && (node->getParent()->getTag())){
			parent=(irr::scene::ISceneNode*)node->getParent()->getTag();
		}
		irr::core::vector2df size=node->getAttVec2F("size",10.0f,10.0f);
		//irr::core::dimension2df(size);
		irr::scene::IBillboardSceneNode*bb=getDevice()->getSceneManager()->addBillboardSceneNode(parent,size);
		readBaseSceneNodeTags(bb,node);
		node->setTag(bb);
		return lampe::xml::NEXT;
	}
};

}//namespace xml
}//namespace lampe

void regBillboard(lampe::xml::IXMLFactoryEnvironment*environment,irr::IrrlichtDevice*d){
	lampe::xml::IFactoryRecord*h=new lampe::xml::BillboardFactory(d);
	environment->registerHandler(h);
	h->drop();
}
